package com.eugenes.concurrency.runnables;

public class SinAdder implements Runnable {

    private final int from;
    private final int to;
    private double result;

    private volatile boolean finished = false;

    public SinAdder(int from, int to) {
        this.from = from;
        this.to = to;
    }

    public double getResult() {
        if (!finished)
            throw new IllegalStateException("Task hasn't finished yet.");

        return result;
    }

    @Override
    public void run() {
        for (int i = from; i <= to; ++i) {
            result += Math.sin(i);
        }
        finished = true;
    }
}